package com.rapid.maintenance.ui.activity.quickpurchase;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.rapid.maintenance.R;
import com.rapid.maintenance.adapter.QuickPurchaseResultAdapter;
import com.rapid.maintenance.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;


public class QuickPurchaseResultActivity extends BaseActivity {
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.bt_search)
    Button btSearch;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.rv_quick_purchase_result)
    RecyclerView rvQuickPurchaseResult;
    QuickPurchaseResultAdapter quickPurchaseResultAdapter;
    private String searchKey;

    @Override
    protected int provideRootLayout() {
        return R.layout.activity_quick_purchase_result;
    }

    @Override
    protected void initializationData(Intent intent) {
        searchKey = intent.getStringExtra("searchKey");
    }

    @Override
    protected void init() {
        setTitle("查询结果");
        setStatusBarColor(0xFF016DB6);
        setToolBarColor(0xFF016DB6);
        rvQuickPurchaseResult.setLayoutManager(new LinearLayoutManager(this));
        rvQuickPurchaseResult.setAdapter(quickPurchaseResultAdapter = new QuickPurchaseResultAdapter());
        etContent.setText(searchKey);
        doSearch(searchKey);
    }

    private void doSearch(String searchKey) {
        this.searchKey = searchKey;
        tvContent.setText(HtmlCompat.fromHtml("您查找的<font color= '#E80000'>“" + searchKey + "”</font>结果如下：", FROM_HTML_MODE_LEGACY));
        List<Object> objects = new ArrayList<>();
        objects.add(new Object());
        objects.add(new Object());
        objects.add(new Object());
        objects.add(new Object());
        objects.add(new Object());
        quickPurchaseResultAdapter.setNewData(objects);
    }

    @OnClick(R.id.bt_search)
    public void onViewClicked() {
        if (TextUtils.isEmpty(etContent.getText())) {
            ToastUtils.showShort("请输入搜索内容");
        } else {
            doSearch(etContent.getText().toString());
        }
    }
}
